<template>
</template>

<script>
	import {login} from "@/utils/api.js";
	
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			let code = this.getCurrentPathParams("code", 0);
			if (code !== 0) {
				this.loginData(code)
			}
		},
		onUnload() {
			this.$storage.clearCurrentPath()
		},
		methods: {
			/**
			 * 登录
			 */
			loginData(code) {
				const url = this.$storage.getCurrentPath();
				login(code).then(res => {
					this.$st.success("登录成功", () => {
						uni.reLaunch({
							url: url
						})
					})
				})
			},
			
			/**
			 * 获取当前路径下的参数
			 */
			getCurrentPathParams(name, value) {
				var newObj = this.getCurrentLinkParams();
				var result = newObj[name];
				if (result === undefined) {
					return value;
				}
				try {
					result = decodeURIComponent(result);
				} catch (e) {
					console.log(e);
				}
				return result;
			},
			/**
			 * 获取当前路径
			 */
			getCurrentLinkParams() {
				var url = location.search;
				var newObj = new Object();
				if (url.indexOf("?") != -1) {
					var str = url.substr(1);
					var strs = str.split("&");
					for (var i = 0; i < strs.length; i++) {
						newObj[strs[i].split("=")[0]] = strs[i].split("=")[1];
					}
				}
				return newObj;
			},
		}
	}
</script>

<style>
</style>